package com.future.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @author zlb
 * @date 2022/4/20 11:04
 */
@Configuration
public class PathConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String os = System.getProperty("os.name");
        //如果是Windows系统
        if (os.toLowerCase().startsWith("win")) {
            // 头像路径映射
            registry.addResourceHandler("/photo/user/avatar/**")
                    // /photo/** 表示在磁盘photo目录下的所有资源会被解析为以下的路径
                    .addResourceLocations("file:C:\\images\\user\\head\\");

            // 监控图像路径映射
            registry.addResourceHandler("/photo/monitor/**")
                    // /photo/** 表示在磁盘photo目录下的所有资源会被解析为以下的路径
                    .addResourceLocations("file:C:\\images\\monitor\\driving\\");

        } else {
            //linux 和mac
            registry.addResourceHandler("/photo/**")
                    .addResourceLocations("file:/www/wwwroot/observer/images/user/head");

        }
    }
}
